package com.alog.yzd.bookmall.service.book;

import com.alog.yzd.bookmall.dao.book.BookDao;
import com.alog.yzd.bookmall.domain.book.Book;
import com.alog.yzd.bookmall.pager.PageBaen;

import java.sql.SQLException;

public class BookService {
    private BookDao bookDao = new BookDao();

    /**
     * 删除图书
     */
    public void delete(String bid){
        try {
            bookDao.delete(bid);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 编辑图书
     */
    public void edit(Book book){
        try {
            bookDao.edit(book);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 添加图书
     */
    public void add(Book book){
        try {
            bookDao.add(book);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 查找某个分类下的图书和数量
     */
    public int findbookCountByCatagory(String cid){
        try {
            return bookDao.findBookCountByCatagory(cid);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 通过BookId查询
     * @param bid
     * @return
     */
    public Book load(String bid){
        try {
            return bookDao.findByBid(bid);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 根据分类查询
     * @param cid
     * @param pc
     * @return
     */
    public PageBaen<Book> findByCatagory(String cid , int pc){
        try {
            return bookDao.findByCatagory(cid,pc);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 根据书名查询
     * @param bname
     * @param pc
     * @return
     */
    public PageBaen<Book> findByBname(String bname , int pc){
        try {
            return bookDao.findByBname(bname,pc);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 根据作者查询
     * @param author
     * @param pc
     * @return
     */
    public PageBaen<Book> findByAuthor(String author , int pc){
        try {
            return bookDao.findByAuthor(author,pc);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 根据出版社查询
     * @param press
     * @param pc
     * @return
     */
    public PageBaen<Book> findByPress(String press , int pc){
        try {
            return bookDao.findByPress(press,pc);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    /**
     * 多条件组合查询
     */
    public PageBaen<Book> findByCombination(Book book , int pc){
        try {
            return bookDao.findByCombination(book,pc);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
